import 'package:intl/intl.dart';

class TimeUtil {
  static String getTimeAgo(double timestamp) {
    DateTime givenTime =
    DateTime.fromMillisecondsSinceEpoch(timestamp.toInt() * 1000);
    DateTime now = DateTime.now();
    Duration difference = now.difference(givenTime);

    if (difference.inSeconds < 60) {
      return "刚刚";
    } else if (difference.inMinutes < 60) {
      return "${difference.inMinutes}分钟前";
    } else if (difference.inHours < 24) {
      return "${difference.inHours}小时前";
    } else if (difference.inDays < 7) {
      return "${difference.inDays}天前";
    } else {
      return DateFormat('yyyy-MM-dd').format(givenTime);
    }
  }
}
